# -*- coding: utf-8 -*-
'''
Created on 2011-3-21
发送私信邀请用户加入活动
@author: Tony
'''
import unittest
from goplay.weibopy.auth import OAuthHandler
from goplay.weibopy.api import API

class messages(unittest.TestCase):
    
    consumer_key= "3482834712"
    consumer_secret ="40c54f7f6730f543aed36b36f92ca06e"
    
    def __init__(self):
            """ constructor """
    
    def getAtt(self, key):
        try:
            return self.obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
        
    def getAttValue(self, obj, key):
        try:
            return obj.__getattribute__(key)
        except Exception, e:
            print e
            return ''
    def setToken(self, token, tokenSecret):
        self.auth = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.auth.setToken(token, tokenSecret)
        self.api = API(self.auth)
    
    def newMessages(self,username,message):
        status=self.api.new_direct_message(screen_name=username,text=message)
        self.obj=status
        return 'successfully'
    
    def send(self,token,tokenSecret,username,message):
        m=messages()
        m.setToken(token, tokenSecret)
        m.newMessages(username, message)
        return 'successfully'

''''m=messages()
u=m.send("3d6bf54fce077e12f236e67a2ef6e886", "fea2e9c69bae15088bf9aa116c371ea8",'草根财经','测试一下啊～～～')
print u'''